package com.example.demo2.controller;

import com.example.demo2.pojo.PageBean;
import com.example.demo2.pojo.vo.SupplierVO;
import com.example.demo2.utils.Result;
import com.example.demo2.pojo.vo.RepairVO;
import com.example.demo2.service.RepairService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/** 
 * <br/>
 * Created by weidong on 2020/02/22
 */
@Controller
public class RepairController {

	@Resource
	private RepairService repairService;
	@RequestMapping("/repair_list")
	public String repairList(Integer number, @RequestParam(defaultValue = "1") Integer currentPage, Model model) throws Exception {
		RepairVO repairVO = new RepairVO();
		repairVO.setENumber(number);
		repairVO.setCurrentPage(currentPage);
		PageBean pageBean=repairService.listPage(repairVO);
		model.addAttribute("pageBean", pageBean);
		model.addAttribute("query", repairVO);
		return "repair_list";
	}
	@RequestMapping("/repair_list/add")
	@ResponseBody
	//添加
	public Result add(String repairname,String repairdate,String repairphone,Integer repairnumber)throws Exception{
		RepairVO repairVO=new RepairVO();
		repairVO.setRName(repairname);
		repairVO.setRDate(repairdate);
		repairVO.setRPhone(repairphone);
		repairVO.setENumber(repairnumber);
		return repairService.add(repairVO);
	}


	@RequestMapping("/repair_list/delete/{id}")
	@ResponseBody
	//删除
	public Result deleteById(@PathVariable("id") Integer id)throws Exception{
		Result result = repairService.deleteById(id);
		Integer code = result.getCode();
		if (code==200){
			repairService.deleteById(id);
		}
		return result;
	}


	@RequestMapping("/repair_list/update")
	@ResponseBody
	//更新
	public Result updateById(Integer id,String repairname2,String repairphone2,String repairdate2,Integer repairnumber2)throws Exception{
		RepairVO repairVO=new RepairVO();
		repairVO.setId(id);
		repairVO.setRName(repairname2);
		repairVO.setRPhone(repairphone2);
		repairVO.setENumber(repairnumber2);
		repairVO.setRDate(repairdate2);
		return repairService.updateById(repairVO);
	}
	/*更新回显
	 * */
	@RequestMapping("/repair_list/find/{id}")
	@ResponseBody
	public Result findClass(@PathVariable("id")Integer id)throws Exception{
		return repairService.findById(id);
	}



}